package com.ybfenpan.controller.core;

import com.ybfenpan.service.core.BaseService;
import com.ybfenpan.utils.MapUtil;
import com.ybfenpan.utils.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

@Controller
@RequestMapping("/Common")
public class CommonController extends BaseController {
	
	@Resource
	private BaseService baseService;

	@RequestMapping("/demo.shtml")
	@ResponseBody
	public void demo(HttpServletRequest request, HttpServletResponse response) {
		boolean retFlag = false;
		Object retObj = "操作成功!";
		try{
			//获取参数
			HashMap formMap = getParameterMap(request);

			String id2Val = MapUtil.getString(formMap,"id2Val");
			if(StringUtil.isNotBlank(id2Val)){
				//解码，ajaxUrlToServer提交的情况
				id2Val = StringUtil.decodeToUTF8(id2Val);
			}

//			//调用数据库
//			baseService.createInfo("create",formMap);
			retFlag = true;
			retObj = formMap;//返回可以是字符串或任意对象
		}catch (Exception ex){
			retObj = "操作失败!\r\n"+ex.getMessage();
		}
		renderSuccess(response, retFlag, retObj);
	}

}
